package arithmetic2;

import utils.PrintUtil;

/**
 * @author Ajie
 * @date 4/27/21
 * @function easy 226. 翻转二叉树
 * https://leetcode-cn.com/problems/invert-binary-tree/
 */
public class T_226_InvertTree {
    public static void main(String[] args) {

        TreeNode treeRootNode = TreeNode.getTreeRootNode();
        PrintUtil.print(treeRootNode);
        TreeNode treeNode = invertTree(treeRootNode);

        PrintUtil.print(treeNode);
    }

    public static  TreeNode invertTree(TreeNode root) {
        dfs(root);

        return root;
    }

    private static void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        TreeNode left = root.left;
        root.left = root.right;
        root.right = left;

        dfs(root.left);
        dfs(root.right);
    }
}
